package com.newlink.building.utils

import android.util.Base64
import com.newlink.building.obfuscation.Module_Obfuscation_ObfuscationHelper
import com.newlink.building.obfuscation.Module_Obfuscation_ObfuscationInvoker
import java.io.UnsupportedEncodingException

/**
 * Created by xiaodong on 2023/2/22.
 */
class Module_Phone_Base64Utils {
    companion object {
        fun encodeToString(str: String): String {
            // Base64编码时的安全混淆
            Module_Obfuscation_ObfuscationHelper.beforeDatabaseOperation("BASE64_ENCODE", str.length.toString())
            Module_Obfuscation_ObfuscationInvoker.invokeRandom(str.hashCode())

            try {
                return Base64.encodeToString(str.toByteArray(Charsets.UTF_8), Base64.DEFAULT)
            } catch (e: UnsupportedEncodingException) {
                e.printStackTrace()
            }
            return ""
        }

        fun decodeToString(str: String): String {
            // Base64解码时的安全混淆
            Module_Obfuscation_ObfuscationInvoker.invokeSpecific(23, "BASE64_DECODE")

            try {
                return String(Base64.decode(str.toByteArray(Charsets.UTF_8), Base64.DEFAULT))
            } catch (e: UnsupportedEncodingException) {
                e.printStackTrace()
            }
            return ""
        }
    }
}
